package com.itheima.d4_print_stream;

import java.io.*;

/*
    目标：掌握打印流：PrintStream/PrintWriter的用法。
 */
public class PrintTest1 {
    public static void main(String[] args) {
        // PrintStream
        try {
            print1();
            print2();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void print1() throws FileNotFoundException {
        // 1. 创建打印流
        final PrintStream ps = new PrintStream(new FileOutputStream("loo.txt"));

        // 2. 写入数据
        ps.print(666666);
        ps.print("字符串");

        ps.println();

        ps.println("换行之后的输出");
        ps.print(55555);

        // 3. 关闭流
        ps.close();
    }

    public static void print2() throws IOException {
        // 1. 创建打印流
        final PrintWriter pw = new PrintWriter(new FileWriter("loo.txt", true));

        // 2. 写入数据
        pw.print("没有换行的输入");
        pw.println(9999);
        pw.println('黑');
        pw.println("最后的输入");

        // 3. 关闭流
        pw.close();
    }
}
